<template>
  <div style="position: relative">
    <div v-if="rowData.children && rowData.children.length || rowData.formula" @click="openChildren" class="open">{{ showChildren?'-':'+' }}</div>
    <div :class="{'no1':no === 1}" class="reportRow flex flex-row">
      <div class="td fl2 flex a-item ">
        <div :style="{'padding-left':(no-1)*20+'px'}">
          {{ rowData.name }}
        </div>
      </div>
      <div class="td fl1 flex a-item j-content">{{ rowData.rowIndex }}</div>
      <div class="td fl1 flex a-item j-content">{{ rowData.currentPeriodIncurredAmount }}</div>
      <div class="td fl1 flex a-item j-content">{{ rowData.accumulatedAmountOfThisYear }}</div>
    </div>
    <profitStatementRow v-show="showChildren" :row-data="item" v-for="item in rowData.children" :no="no+1"></profitStatementRow>
    <profitStatementRow v-show="showChildren" :row-data="item" v-for="item in rowData.formula" :no="no+1"></profitStatementRow>
  </div>
</template>

<script>
export default {
  name: 'profitStatementRow',
  props:{
    rowData:{
      type: Object,
      default: null
    },
    no:{
      type: Number,
      default: 1
    }
  },
  created() {
    if(this.no < 2)this.showChildren = true
  },
  data(){
    return{
      showChildren:false
    }
  },
  methods:{
    openChildren(){
      this.showChildren = !this.showChildren
    }
  }
}
</script>

<style lang="scss" scoped>
.reportRow{
 .td{
   border: 1px solid #000000;
    overflow: hidden;
   height: 30px;
 }
}
.no1{
  background-color: #BDD7EE;
}
.open{
  position: absolute;
  margin-left: -20px;
  font-size: 20px;
  cursor: pointer;
}
</style>
